﻿using System.Collections.Generic;
using System.Reflection;

namespace BorgExt
{
    public abstract class InitializerBase
    {
        protected readonly Runtime runtime;

        protected InitializerBase(RuntimeConfig config)
        {
            runtime = new Runtime(config);
        }

        protected void Start(ICollection<Contract> contracts, ICollection<Plugin> plugins,
            ExtensionType startup, IEnumerable<LogEventArgs> initialLogs)
        {
            runtime.Start(contracts, plugins, startup, initialLogs);
        }

        protected bool Analyze(Assembly assembly, List<Contract> contracts, List<Plugin> plugins)
        {
            Contract contract;
            Plugin plugin;

            if (!AssemblyAnalyzer.Analyze(assembly, runtime.DiscoveryCore.TypeBuilder, out contract, out plugin))
                return false;

            if (contract != null)
                contracts.Add(contract);

            if (plugin != null)
                plugins.Add(plugin);

            return true;
        }
    }
}

